package cn.netswap.jeegorilla.framework.config;

import cn.netswap.jeegorilla.framework.intercepter.GorillaIntercepter;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by lai_gw on 2020/3/16.
 * WebMvcConfigurer统一配置类
 */
@Configuration
public class GorillaWebMvcConfigurer implements WebMvcConfigurer {

    /**
     * 拦截器的配置
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new GorillaIntercepter()).addPathPatterns("/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }

    /**
     * 资源放行处理
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/**");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }

    /**
     * 默认控制器
     * 根据mapping 跳到视频上
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/loginPage").setViewName("/tologin");
        registry.addViewController("/index").setViewName("/index");
        registry.addViewController("/").setViewName("/index");
        registry.addViewController("/getUserList").setViewName("/userList");
        registry.addViewController("/getOrderList").setViewName("/orderList");
        registry.addViewController("/signup").setViewName("/socailbinding");
        registry.addViewController("/socialRegisterSuccess").setViewName("/socialRegisterSuccess");
        registry.addViewController("/sessionInvaid").setViewName("/sessionInvaidPage");
        registry.addViewController("/logoutPage").setViewName("/logoutPage");
    }

}
